<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link rel="stylesheet" type="text/css" href="style.css" />
		<title>项目管理系统</title>
		<script src="./jQuery/jquery-1.8.0.js"></script>
		<script src="util.js"></script>
		<script src="query.js"></script>
		<script src="insert.js"></script>
	</head>
	<body onload="onLoad()">
		<?php
			require_once("connect_sql.php");
		?>
	
	<div id="userInfo">
	</div>
	<div id="head">
		<ul id="menu">
			<li id="all"><a href="index.php" title="查看项目">查看项目</a></li>
			<li id="add"><a href="add.php" title="添加项目">添加项目</a></li>
			<li id="update"><a href="update.php" title="更新项目">更新项目</a></li>
			<li id="property"><a href="property.php" title="属性管理">属性管理</a></li>
		</ul>
	</div>
	
	<div id="search">
		<h1>请按条件输入需要更新的项目</h1>
		<span>主板名：</span><select id="select_board" name="board" onChange="updateOnBoardChange(this.value)"><option value="empty">请选择主板</option></select>
		&nbsp;&nbsp;<span>客户名：</span><select id="select_customer" name="custom" onChange="updateOnCustomChange(this.value)"><option value="empty">请选择主板</option></select>
		&nbsp;&nbsp;<span>商业名：</span><select id="select_business" name="business"><option value="empty">请选择主板</option></select>
	</div>
	<div id="project">
		<table class="table1">
			<tr>
				<td>
					<table class="table2">
						<input type="hidden" id="project_id" value=""/>
						<td class="tdLeft"><span>发布人：</span><select id="author" value="">
							<?php
								$sql = 'select distinct * from author';
								$result = mysql_query($sql);
								if(!$result) echo mysql_error();
								printf('<option value="empty"/>==请选择==</option>');
								while($row = mysql_fetch_array($result)) {
									printf('<option value="%d">%s</option>', $row['id'], $row['name']);
								}
							?>
						</select>
						</td>
						<td class="tdCenter"><span>主板型号：</span><input type="text" id="board" value="" onblur="this.value=this.value.toUpperCase()"/></td>
						<td class="tdCenter"><span>客户：</span><select id="customer" value="">
							<?php
								$sql = 'select distinct * from customer';
								$result = mysql_query($sql);
								if(!$result) echo mysql_error();
								printf('<option value="empty"/>==请选择==</option>');
								while($row = mysql_fetch_array($result)) {
									printf('<option value="%d">%s</option>', $row['id'], $row['name']);
								}
							?>
						</select>
						</td>
						<td class="tdRight"><span>商业型号：</span><input type="text" id="business" value=""/></td>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="table2">
						<tr><td class="tdLeft"><span>平&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;台：</span><select class="large" id="platform" value="">
							<?php
								$sql = 'select distinct * from platform';
								$result = mysql_query($sql);
								if(!$result) echo mysql_error();
								printf('<option value="empty"/>==请选择==</option>');
								while($row = mysql_fetch_array($result)) {
									printf('<option value="%d">%s</option>', $row['id'], $row['name']);
								}
							?>
							</select>
						</td></tr>
						<tr><td class="tdLeft"><span>软件时间：</span><input type="text" id="date" name="date" value="" readonly="true" onclick="fPopCalendar(date,date, function() {date.style.color='#f00';});return false"/></td></tr>
						<tr><td class="tdLeft"><span>最新版本：</span><input type="text" class="large" id="lastVersion" value=""/></td></tr>
						<!--<tr><td class="tdLeft"><span>公版软件：</span><input type="text" class="large" id="gbVersion" value=""/></td></tr>-->
						<tr><td class="tdLeft"><span>ATA软件：</span><input type="text" class="large" id="ataVersion" value=""/></td></tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="table2">
						<tr>
							<td class="tdLeft newProjectWidth"><span>RFPA：</span></td>
							<td><div id="divRfpa"></div></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="table2">
						<tr>
							<td class="tdLeft newProjectWidth"><span>功放：</span></td>
							<td><div id="divClassK"></div></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="table2">
						<tr>
							<td class="tdLeft newProjectWidth"><span>软件功能：</span></td>
							<td><div id="divFunction"></div></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="table2">
						<tr>
							<td class="tdLeft newProjectWidth"><span>摄像头：</span></td>
							<td><div id="divCamera"></div></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="table2">
						<tr><td class="tdLeft newProjectWidth"><span>屏：</span></td>
							<td><div id="divLcd"></div></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td align="center"><button class="button updateBtn" onclick="return updateProject();">更新</button></td>
			</tr>
		</table>
	</div>
	<div id='footbar'></div>
	</body>
	
	<!--设置标签页选中CSS-->
	<script type="text/javascript">
		var urlstr = location.href;
		var urlstatus=false;
		$("#menu a").each(function () {
			if ((urlstr + '/').indexOf($(this).attr('href')) > -1 && $(this).attr('href') != '') {
				$(this).addClass('curMenu');
				urlstatus = true;
			} else {
				$(this).removeClass('curMenu');
			}
		});
		if (!urlstatus) {
			$("#menu a").eq(0).addClass('curMenu');
		}
	</script>
	<script type="text/javascript">
		//<!--radio/checkbox Item 点击事件-->
		function loadItems() {
			$("div#divRfpa").load("loadRfpa.php", function() {
				$("div#divClassK").load("loadClassk.php", function() {
					$("div#divFunction").load("loadFunction.php", function() {
						$("div#divCamera").load("loadCamera.php", function() {
							$("div#divLcd").load("loadLcd.php", function() {
								
								$(".radioItem").click(function() {
									with($(this).children('input')) {
										if(attr("checked") == "checked") {
											removeAttr("checked");
										} else {
											attr('checked', 'checked');
										}
										$('input[name=' + attr('name') + ']').each(function() {
											if($(this).attr("checked") == true || $(this).attr("checked") == "checked") {
												$(this).next().css('color', '#f00')
											} else {
												$(this).next().css('color', '#000')
											}
										});
									}
								});
								$(".checkboxItem").click(function() {
									with($(this).children('input'))
									{
										if(attr("checked") == "checked") {
											removeAttr("checked");
										} else {
											attr('checked', 'checked');
										}
									}
									with($(this).children('label'))
									{
										if(css('color') == '#000' || css('color') == 'rgb(0, 0, 0)') {
											css('color', '#f00');
										} else {
											css('color', '#000');
										}
									}
								});
								$("#date").css('color', "#000");
								$("#author,#customer,#platform").change(function() {
									$(this).css('color', '#f00');
								});
							});
						});
					});
				});
			});
		}
		function loadItemsEx() {
			$("div#divRfpa").load("loadRfpa.php", function() {
				$("div#divClassK").load("loadClassk.php", function() {
					$("div#divFunction").load("loadFunction.php", function() {
						$("div#divCamera").load("loadCamera.php", function() {
							$("div#divLcd").load("loadLcd.php", function() {
								
								$(".radioItem").click(function() {
									with($(this).children('input')) {
										if(attr("checked") == "checked") {
											removeAttr("checked");
										} else {
											attr('checked', 'checked');
										}
										$('input[name=' + attr('name') + ']').each(function() {
											if($(this).attr("checked") == true || $(this).attr("checked") == "checked") {
												$(this).next().css('color', '#f00')
											} else {
												$(this).next().css('color', '#000')
											}
										});
									}
								});
								$(".checkboxItem").click(function() {
									with($(this).children('input'))
									{
										if(attr("checked") == "checked") {
											removeAttr("checked");
										} else {
											attr('checked', 'checked');
										}
									}
									with($(this).children('label'))
									{
										if(css('color') == '#000' || css('color') == 'rgb(0, 0, 0)') {
											css('color', '#f00');
										} else {
											css('color', '#000');
										}
									}
								});
								$("#date").css('color', "#000");
								$("#author,#customer,#platform").change(function() {
									$(this).css('color', '#f00');
								});
								
								var obj = GetRequest();
								if(obj != "") {
									$('select_board').attr('value', obj['board']);
									$('select_customer').attr('value', obj['customer']);
									$('select_business').attr('value', obj['business']);
									onProjectLoaded(obj['board'], obj['customer'], obj['business']);
								}
							});
						});
					});
				});
			});
		}
	</script>
	<script type="text/javascript">
		function updateProject() {
			var $author = $("#author").attr("value");
			var $board = $("#board").attr("value");
			var $customer = $("#customer").attr("value");
			var $business = $("#business").attr("value");
			var $platform = $("#platform").attr("value");
			var $date = $("#date").attr("value");
			var $lastVersion = $("#lastVersion").attr("value");
			//var $gbVersion = $("#gbVersion").attr("value");
			var $ataVersion = $("#ataVersion").attr("value");
			var $rfpaID = $("input[name='rfpa']:checked").val();
			var $classKID = $("input[name='classK']:checked").val();
			var $projectID = $("#project_id").attr("value");
			var $function = "";
			var $dataArray = new Array();
			$("input[name='function']:checked").each(function() {
				$dataArray.push($(this).val());
			});
			$function = $dataArray.sort(function(a, b) { return a - b;}).join(',');
			var $camera = "";
			$dataArray.length = 0;
			$("input[name='camera']:checked").each(function() {
				$dataArray.push($(this).val());
			});
			$camera = $dataArray.sort(function(a, b) { return a - b;}).join(',');
			var $lcd = "";
			$dataArray.length = 0;
			$("input[name='lcd']:checked").each(function() {
				$dataArray.push($(this).val());
			});
			$lcd = $dataArray.sort(function(a, b) { return a - b;}).join(',');
			
			var alertStr = "";
			var warningStr = "";
			if($author == "empty") alertStr += "发布人\n";
			if($board == "") alertStr += "主板型号\n";
			if($customer == "empty") alertStr += "客户\n";
			if($business == "") alertStr += "商业型号\n";
			if($platform == "empty") alertStr += "平台\n";
			if($date == "") alertStr += "软件时间\n";
			if($lastVersion == "") alertStr += "最新版本\n";
			//if($gbVersion == "") warningStr += "公板软件\n";
			if($ataVersion == "") warningStr += "ATA软件\n";
			if($function == "") alertStr += "软件功能\n";
			if($camera == "") alertStr += "摄像头\n";
			if($lcd == "") alertStr += "屏\n";
			
			if(alertStr != "") {
				alertStr += "\n不能为空";
				alert(alertStr);
				return;
			}
			if(warningStr != "") {
				warningStr += "\n没有填写，确定不填？";
				var r = confirm(warningStr);
				if(r == false) return;
			}
			
			var $param = "?author=" + $author;
			$param += "&board=" + $board;
			$param += "&customer=" + $customer;
			$param += "&business=" + $business;
			$param += "&platform=" + $platform;
			$param += "&lastDate=" + $date;
			$param += "&lastVersion=" + $lastVersion;
			//$param += "&gbVersion=" + $gbVersion;
			$param += "&ataVersion=" + $ataVersion;
			$param += "&rfpa=" + $rfpaID;
			$param += "&classK=" + $classKID;
			$param += "&function=" + $function;
			$param += "&camera=" + $camera;
			$param += "&lcd=" + $lcd;
			$param += "&id=" + $projectID;
			//onUpdateProject($param);
			
			$.get('insertUpdateProject.php' + $param + '&sid=' + Math.random(),
				function(data, status){
					if(trimStr(status) == 'success' && trimStr(data) == 'successed') {
						alert("项目更新成功!");
						
						resetCSS();
					} else {
						alert("项目更新失败！！！");
					}
				}
			);
		}
		
		$('#userInfo').load('loadUserInfo.php', function() {
			if(getCookie('login') && getCookie('login') == 'true') {
				$('a#user').text(getCookie('nickname'));
			} else {
				location.href = 'login.html';
			}
		});
		$('#select_business').change(function() {
			reset();
			if($('#select_business').attr('value') != 'empty') {
				onProjectLoaded($('#select_board').attr('value'), $('#select_customer').attr('value'), $('#select_business').attr('value'));
			}
		});
		function onProjectLoaded(board, customer, business) {
			$.get('queryProject.php?board=' + board + 
				'&customer=' + customer + 
				'&business=' + business,
				function(data, status){
					var sub = trimStr(data).split('|');
					var i = 0;
					if(status == 'success') {
						$('#project_id').attr('value', sub[i++]);
						$('#author').attr('value', sub[i++]);
						$('#board').attr('value', sub[i++]);
						$('#customer').attr('value', sub[i++]);
						$('#business').attr('value', sub[i++]);
						$('#platform').attr('value', sub[i++]);
						$('#date').attr('value', sub[i++]);
						$('#lastVersion').attr('value', sub[i++]);
						$('#ataVersion').attr('value', sub[i++]);
						$('input[name=rfpa][value='+ sub[i++] +']').attr('checked', 'checked');
						$('input[name=classK][value='+ sub[i++] +']').attr('checked', 'checked');
						var data = trimStr(sub[i++]).split(',');
						for(var j = 0; j < data.length; j++) {
							$('input[name=function][value='+data[j]+']').attr('checked', 'checked');
						}
						var data = trimStr(sub[i++]).split(',');
						for(var j = 0; j < data.length; j++) {
							$('input[name=camera][value='+data[j]+']').attr('checked', 'checked');
						}
						var data = trimStr(sub[i++]).split(',');
						for(var j = 0; j < data.length; j++) {
							$('input[name=lcd][value='+data[j]+']').attr('checked', 'checked');
						}
					}
				});
		}
		
		function reset() {
			resetCSS();
			
			var $author = $("#author").attr("value", "empty");
			var $board = $("#board").attr("value", "");
			var $customer = $("#customer").attr("value", "empty");
			var $business = $("#business").attr("value", "");
			var $platform = $("#platform").attr("value", "empty");
			var $lastDate = $("#date").attr("value", "");
			var $lastVersion = $("#lastVersion").attr("value", "");
			//var $gbVersion = $("#gbVersion").attr("value", "");
			var $ataVersion = $("#ataVersion").attr("value", "");
			
			$(".radioItem").children("input").removeAttr("checked");
			$(".checkboxItem").children("input").removeAttr("checked");
		}
		function resetCSS() {
			$('.radioItem label').css('color', '#000');
			$('.checkboxItem label').css('color', '#000');
			$('#data').css('color', '#000');
			$('#autor, #customer, #platform').css('color', '#000');
			$('input[type=text]').css('color', '#000');
		}
		
		function GetRequest() {
			var url = location.search; //获取url中"?"符后的字串
			var theRequest = new Object();
			if (url.indexOf("?") != -1) {
				var str = url.substr(1);
				strs = str.split("&");
				for (var i = 0; i < strs.length; i++) {
					theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
				}
			}
			return theRequest;
		}
		function onLoad() {
			var obj = GetRequest();
			if(obj.board) {
				$('#search').hide();
				loadBoardData(loadItemsEx);
			} else {
				$('#search').show();
				loadBoardData(loadItems);
			}
		}
	</script>
</html>